<template>
	<view class="container">
		<input type="text" class="input" :placeholder="`请输入${hint}`" placeholder-style="color:#BBBBBB;font-size:28rpx"
			v-model="nickname" maxlength="15"></input>
		<button class="set-btn" form-type="submit" @click="onSub">保
			存</button>
	</view>
</template>

<script>
	import {
		changeNickName,
		setStoreMsg
	} from "../../../api/index.js"
	export default {
		data() {
			return {
				hint: '昵称',
				nickname: '',
				pageType: '', //两种type,一种是个人中心的修改昵称,一种是商家修改店铺名称
				bid: "",
			};
		},

		onLoad(opt) {
			this.pageType = opt.pageType
			this.bid = opt.bid
			if (this.pageType == '店铺名称') {
				this.hint = this.pageType
				this.setNavTitle = '店铺名称'
				this.bid = opt.bid
			}
		},
		methods: {

			// 修改店铺信息
			async onSetStoreMsg() {
				const res = await setStoreMsg(`s=/ApiBusiness/setinfo`, {
					bid: this.bid,
					name: this.nickname
				})
				const {
					data,
					msg,
					status
				} = res.data
				this.showToast(msg)
				if (status == 1) {
					this.goBack(2000)
					console.log(res.data)
				}
			},
			async onChangeNickName() {
				const res = await changeNickName('s=ApiMy/setfield', {
					nickname: this.nickname
				})
				const {
					status,
					msg
				} = res.data
				this.showToast(msg)
				if (status == 1) {
					this.goBack(2000)
				}
			},

			async onSub() {
				if (this.nickname == '') {
					this.showToast(`请输入${this.hint}`)
				} else {
					this.pageType == '店铺名称' ? this.onSetStoreMsg() : this.onChangeNickName()
				}

			},
		}
	};
</script>
<style>
	.set-btn {
		width: 90%;
		margin: 60rpx 5%;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 48rpx;
		color: #FFFFFF;
		font-weight: bold;
		background: #41644A;
	}

	.input {
		margin: 100rpx 30rpx;
		background: #f7f7f7;
		height: 96rpx;
		padding: 0 30rpx;
		width: 85vw;

	}
</style>
